package com.jxwifi.cloud.quickclean.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.bean.OrderContainBean;
import com.jxwifi.cloud.quickclean.bean.StrListBean;

import java.util.ArrayList;
import java.util.List;

public class TkDetailsAdapter extends BaseQuickAdapter<OrderContainBean, BaseViewHolder> {

    public TkDetailsAdapter(@LayoutRes int layoutResId, @Nullable List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderContainBean item) {

        Glide.with(mContext).load(item.getImgUrl()).error(R.mipmap.icon_default_head).into((ImageView) helper.getView(R.id.img_pop_kit_items_images));
        helper.setText(R.id.tv_pop_kit_items_name, item.getName());
        if (!TextUtils.isEmpty(item.getJsonStr())) {
            List<StrListBean> mList = new ArrayList<>();
            mList = JSON.parseArray(item.getJsonStr(), StrListBean.class);
            String Specifications = "";
            for (int i = 0; i < mList.size(); i++) {
                Specifications = Specifications + "" + mList.get(i).getKey() + ":" + mList.get(i).getValue();
            }
            helper.setText(R.id.tv_pop_kit_items_specifications, "规格：" + Specifications);
        } else {
            helper.setText(R.id.tv_pop_kit_items_specifications, "规格：暂无");
        }
        helper.setText(R.id.tv_pop_kit_items_price, "\u00A5" + String.valueOf(item.getDiscountValue()));
        helper.setText(R.id.tv_pop_kit_item_num, "x" + item.getNumber());

        helper.addOnClickListener(R.id.rel_details_kit_items);
    }
}
